package com.ias.business.testbiz.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加分页插件，指定数据库类型（例如 MySQL）
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 设置单页的最大条数，防止恶意查询
        paginationInterceptor.setMaxLimit(1000L);
        // 设置溢出总页数后是否进行处理(默认不处理)
        paginationInterceptor.setOverflow(false);
        // 优化JOIN查询
        paginationInterceptor.setOptimizeJoin(true);

           interceptor.addInnerInterceptor(paginationInterceptor);
        // 2. 乐观锁插件 - 支持version字段自动更新
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
